package cn.mumzone.pos.presenter;

import cn.mumzone.basic.mvp.AbsPresenter;
import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.net.response.PageListResponse;
import cn.mumzone.pos.AppConstants;
import cn.mumzone.pos.model.RepoListGoodsEntity;
import cn.mumzone.pos.model.source.GoodsRepository;
import cn.mumzone.pos.model.source.StockRepository;
import cn.mumzone.pos.presenter.contract.StockInOtherTypeSearchContract;
import cn.mumzone.pos.presenter.contract.StockOutSearchContract;

/**
 * Created by qiuzhenhuan on 2019/7/31.
 */

public class StockInOtherTypeSearchPresenter extends AbsPresenter<StockInOtherTypeSearchContract.View, StockRepository> implements StockInOtherTypeSearchContract.Presenter {

    private int mPageNum = 1;

    GoodsRepository goodsRepository;

    @Override
    protected void initOtherRepository() {
        super.initOtherRepository();
        goodsRepository = new GoodsRepository();
    }

    @Override
    public void loadRepoGoodsById(String repositoryId, String classifyId, String keyword, boolean isScan, final boolean isRefresh,String type) {
        if (isRefresh) {
            mPageNum = 1;
        } else if (isScan) {
            mPageNum = 2;
        }
        ApiCallBack<PageListResponse<RepoListGoodsEntity>> callBack = new ApiCallBack<PageListResponse<RepoListGoodsEntity>>() {
            @Override
            public void onSuccess(PageListResponse<RepoListGoodsEntity> response) {
                mView.showGoodsList(response.getList(), isRefresh);
                mPageNum++;
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };

        mRepo.findRepoGoodsByRepoId(repositoryId, classifyId, keyword,
                String.valueOf(mPageNum), String.valueOf(AppConstants.PAGE_SIZE),type, callBack);
        addSubscrebe(callBack);
    }

}
